package semantic.search.logos.foundation.dataprovider.relational;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class SQLConnection {

	private static SQLConnection instance;
	private Connection connection;
	
	public static SQLConnection instance()
	{
		if (instance == null)
			instance = new SQLConnection();
		
		return instance;
	}
	
	// ------------------------------------
	
	public SQLConnection()
	{
		connect();
	}
	
	public void connect()
	{
		 String url = "jdbc:mysql://localhost:3306/";
         String dbName = "jena";
         String driver = "com.mysql.jdbc.Driver";
         String userName = "root";
         String password = "smleslmpep";
         
         try {
        	 
	         Class.forName(driver).newInstance();
	         connection = DriverManager.getConnection(url+dbName,userName,password);
	          	        
         } catch (Exception e) {
        	 e.printStackTrace();
         }
    }
	
	public ResultSet query(String SQL)
	{
		try {
			Statement st = connection.createStatement();
        	return st.executeQuery(SQL);
		} catch (Exception e) {
			e.printStackTrace();
        }
		
		return null;
	}
		
	public void close()
	{
		 try {
			 connection.close();
		 } catch (Exception e) {
        	 e.printStackTrace();
         }
	}
}
